<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('园所信息列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>园所名称：</label>
                            <input type="text" name="areaName"/>
                            <input type="hidden" name="groupId" id="groupId" th:value="${groupId}"/>
                        </li>
                        <li>
                            <label>集团名称：</label>
                            <input type="text" name="params[groupName]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addTab()" >
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.editTab()" >
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" >
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" >
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('sso:area:edit')}]];
    var removeFlag = [[${@permission.hasPermi('sso:area:remove')}]];
    var prefix = ctx + "sso/area";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            resetUrl: prefix + "/resetRoleList",
            modalName: "园所信息",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '园区id',
                },
                {
                    field: 'areaName',
                    title: '园所名称'
                },
                {
                    field: 'adminStaffName',
                    title: '主管理员'
                },
                {
                    field: 'groupName',
                    title: '上级机构'
                },
                {
                    field: 'mobile',
                    title: '联系方式'
                },
                {
                    field: 'pcaCodeDesc',
                    title: '地址码'
                },
                {
                    field: 'address',
                    title: '详细地址'
                },
                {
                    field: 'longtitude',
                    title: '经度/纬度',
                    formatter: function(value, row, index) {
                        return getLatitude( row.longtitude,row.latitude);
                    }
                },
                {
                    field: 'areaCover',
                    title: '园区主图',
                    formatter: function(value, row, index) {
                        return getImg( row.areaCover);
                    }
                },
                {
                    field: 'logo',
                    title: '园区logo',
                    formatter: function(value, row, index) {
                        return imgs( row.logo);
                    }
                },

                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.recipes==0){
                            actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="tongbangCreate(\'' + row.id +'\')">创建食谱</a> ');
                        }
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="areaByRoleList(\'' + row.id +'\')">角色列表</a> ');
                        actions.push('<a class="btn btn-success btn-xs  " href="javascript:void(0)" onclick="resetRoleList(\'' + row.id + '\')"><i class="fa fa-edit"></i>重置角色列表</a> ');
                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="authUser(\'' + row.id +'\')">园区用户</a> ');
                        actions.push('<a class="btn btn-success btn-xs  " href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="liveRoom(\'' + row.id +'\')">摄像头列表</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /* 园区管理-分配用户 */
    function authUser(id) {
        var url = prefix + '/authUser/' + id;
        $.modal.openTab("分配用户", url);
    }
    /* 园区管理-角色列表 */
    function areaByRoleList(id) {
        var url = prefix + '/areaByRoleList/' + id;
        $.modal.openTab("园区角色列表", url);
    }

    /**
     * 创建童帮食谱
     * @param id
     */
    function tongbangCreate(id) {
        $.modal.confirm("确认创建食谱吗？", function() {
            $.operate.post("/sso/tongbang/create", { "areaId": id });
        })
    }
    function resetRoleList(id) {
        $.modal.confirm("确认重置园区的所有角色？", function() {
            $.operate.post("/sso/area/resetRoleList", { "areaId": id });
        })
    }
    /* 园区管理-角色列表 */
    function liveRoom(id) {
        var url =  '/sso/liveRoom?areaId=' + id;
        $.modal.openTab("摄像头列表", url);
    }

    /* 图片集合 */
    function imgs(logo) {
        if (logo == null || logo == ""){
            return  "";
        }
        // https://saas.res.dotflat.cn/teach/file/course/common/admin_1653449157903.jpeg,https://saas.res.dotflat.cn/teach/file/course/common/admin_1653449162302.jpeg,https://saas.res.dotflat.cn/teach/file/course/common/admin_1653449165912.jpeg
        var logos = logo.split(",");
        var html = "";
        for (let i = 0; i <logos.length ; i++) {
            html += '<img src="' + logos[i] + '" height="90" width="90">';
        }
        return html;
    }
    function getImg(img) {
        if (img == null || img == ""){
            return  "";
        }
        return '<img src="' + img + '" height="120" width="120">';
    }

    function getLatitude(longtitude,latitude) {
        return '<p>'+longtitude+'</p><p>'+latitude+'</p>';
    }

</script>
</body>
</html>